package com.easysoft.framework.quartz.scheduling;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.SchedulerException;
import org.springframework.context.ApplicationContext;

public abstract class AbstractJob implements Job {

	private static final String APPLICATION_CONTEXT_KEY = "applicationContext";

	protected final ApplicationContext getApplicationContext(JobExecutionContext context) throws SchedulerException {
		ApplicationContext appCtx = null;
		appCtx = (ApplicationContext) context.getScheduler().getContext().get(APPLICATION_CONTEXT_KEY);
		if (appCtx == null) {
			throw new JobExecutionException(
					"No application context available in scheduler context for key \"" + APPLICATION_CONTEXT_KEY + "\"");
		}
		return appCtx;
	}

}
